﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 学生选课及成绩查询管理系统
{
    public partial class updateGradeInfo : Form
    {
        public updateGradeInfo()
        {
            InitializeComponent();
        }

        private void txt_cno_Click(object sender, EventArgs e)
        {
            //string stuno = txt_stuno.Text;
            //if (stuno == "")
            //{
            //    return;
            //}
            //string sql = "select count(*) from dbo.student where stuno=@stuno";
            //SqlParameter[] arraysql = { new SqlParameter("@stuno", stuno) };

            //object o = DBAccess.GetOne(sql, arraysql);
            //if ((int)o == 1)
            //{
            //    txt_tishi1.Text = "✓";
            //    txt_tishi1.ForeColor = Color.Green;
            //}
            //else
            //{
            //    MessageBox.Show("请输入正确的学号");
            //    txt_stuno.Focus();
            //    return; 
            //}
        }

        private void btn_sub_Click(object sender, EventArgs e)
        {
            string stuno = txt_stuno.Text;
            string cno = txt_cno.Text;
            string score = txt_score.Text;
            if(string.IsNullOrEmpty(stuno)||string.IsNullOrEmpty(cno)||string.IsNullOrEmpty(score)){
                MessageBox.Show("请输入完整信息");
                return;
            }
            string sql = "update grade set score=@score where stuno=@stuno and cno = @cno";
            SqlParameter[] sqlarray = { new SqlParameter("@score", score), new SqlParameter("@stuno", stuno),
                                      new SqlParameter("@cno",cno) };
            int res = DBAccess.GetState(sql,sqlarray);
            if(res!=0){
                MessageBox.Show("修改成功");
            }else{
                MessageBox.Show("该学生没有此课程或学生学号填写错误。请核实后再进行修改");
                return;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
